<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>Document</title>
</head>
<body>
    https://autumnfish.cn/api/joke/list?num=3
    <div id="app">
         <h1>  用户名 </h1>
         <input type="text" v-model.lazy='uname'>
         <p>{{ tip }}</p>
    </div>
</body>
<script>
var vm = new Vue({
    el: "#app",
    data: {
       uname:'',
       tip: '',
       
    },
    watch:{
        uname: function(v){
            console.log( '更新为=' + v);
            this.tip = '正在验证...';
            // ajax请求
            this.checkName(v);
        }  
    },
    methods:{
        checkName(v){
            //用定时器模拟 ajax
            console.log( '-------');
            setTimeout(()=>{
               if(v == 'admin'){
                  console.log( this );
                  this.tip  = '这个名字不能使用'
               }else{
                  this.tip  = '可用'
               }
            },2000);
        }
    }
});
</script>
</html>